﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// MediaUtil 的摘要说明
/// </summary>
public class MediaUtil
{
    #region cookies顺序
    public const int UID = 0;
    public const int UIDX = 1;
    public const int ULEVEL = 2;
    public const int UVIP = 3;
    public const int USEC = 4;
    public const int UIP = 5;
    public const int USTAGE = 6;
    public const int UMYNAME = 7;
    public const int UPHOTO = 8;
    public const int UVIDEO = 9;
    public const int USEX = 10;
 public const int IsHome = 12;
    #endregion
	public MediaUtil()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}

    #region 查看cookies个人信息，无cookie返回"-1";
    /// <summary>
    /// 示例
    /// </summary>
    /// <example> 
    /// string strCookie = MediaUtil.ReturnInfo(MediaUtil.UID);  //取用户名
    /// string strCookie = MediaUtil.ReturnInfo(MediaUtil.UIDX); //取用户IDX
    /// </example>
    /// <returns>字符串类型</returns>
    public static string ReturnInfo(int num)
    {
        HttpCookie cookie1 = HttpContext.Current.Request.Cookies["C_info"];

        if (cookie1 == null)
        {
            return "-1";
        }
        else
        {
            string str1 = encrypttools.Decrypt(cookie1.Value, encrypttools.myKey);
            string[] strcookie = str1.Split(',');
            return strcookie[num];
        }
    }
    #endregion
    #region  查看cookies，是否登录,得到用户myname
    public static string ReturnUserMyname()
    {
        string strCookie = ReturnInfo(UMYNAME);
        if (strCookie == "-1")
        {
            //HttpContext.Current.Response.End();
            return "-1";
        }

        else
            return strCookie;

    }
    #endregion
    #region  查看cookies，是否登录,得到用户ID
    public static string ReturnUserID()
    {
        string strCookie = ReturnInfo(UID);
        if (strCookie == "-1")
        {
            //HttpContext.Current.Response.End();
            return "-1";
        }

        else
            return strCookie;

    }
    #endregion

    #region  查看cookies，是否登录,得到Idx
    public static int ReturnMemberId()
    {
        string strCookie = ReturnInfo(UIDX);
        if (strCookie == "-1")
        {
            return 0;
        }
        else
            return Convert.ToInt32(strCookie);


    }
    #endregion

    #region  查看cookies，取得用户等级
    public static int ReturnLevel()
    {
        string strCookie = ReturnInfo(ULEVEL);
        if (strCookie == "-1")
        {
            return 0;
        }
        else
        {
            return Convert.ToInt32(strCookie);
        }
    }
    #endregion

    #region 查看cookie 得到姓名
    public static string ReturnUserName()
    {
        try
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies["mycookies"];
            if (cookie == null)
            {

                return "null";
            }
            else
            {
                if (cookie.Values["myname"] == null)
                    return "null";
                else
                    return HttpUtility.UrlDecode(cookie.Values["myname"].ToString(), System.Text.Encoding.GetEncoding("gb2312"));
            }
        }
        catch
        {
            return "null";
        }
        //HttpUtility.UrlDecode(oo,System.Text.Encoding.Default);   
    }
    #endregion
  #region  得到登录令牌
    public static string ReturnSec()
    {
        string strCookie = ReturnInfo(USEC);
        if (strCookie == "-1")
        {
            //HttpContext.Current.Response.End();
            return "-1";
        }

        else
            return strCookie;
    }
    #endregion
    #region 得到用户昵称
    public static string ReturnName()
    {
        string strCookie = ReturnInfo(UMYNAME);
        if (strCookie == "-1")
        {
            //HttpContext.Current.Response.End();
            return "-1";
        }

        else
            return strCookie;
    }
    #endregion

    #region 得到记录类别 
    public static int ReturnSaveType()
    {
        string strCookie = ReturnInfo(IsHome);
        if (strCookie == "-1")
        {
            //HttpContext.Current.Response.End();
            return 0;
        }

        else
            return int.Parse(strCookie);
    }
    #endregion

}
